import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useCommonStore = defineStore(
  'common',
  () => {
    // 配置信息
    const config = ref({
      web_site_logo: '',
      cookies: '',
      refunds: '',
      terms: '',
      privacy_policy: '',
      gold_introduce: '',
      where_play: '',
      footer_url: [],
    })

    const setConfig = (conf) => {
      config.value = conf
    }

    const payList = ref([])
    const setPayList = (list) => {
      payList.value = list
    }

    // 游戏列表
    const gameList = ref([])
    const setGameList = (list) => {
      gameList.value = list
    }

    // 选中的游戏
    const selectedGame = ref({
      key: '',
      label: 'Select Game',
    })

    // 选中的区服
    const selectedArea = ref({
      key: '',
      label: 'Select Area',
    })

    const switchGameArea = (info, type = 'game') => {
      if (type === 'game') {
        selectedGame.value = info
        selectedArea.value = {
          key: '',
          label: 'Select Area',
        }
      } else selectedArea.value = info
    }

    // 选中的分类
    const selectedCategory = ref({
      // 展开的菜单
      openKeys: [],
      // 选中的分类
      keys: [],
    })

    const switchCategory = (info) => {
      selectedCategory.value = info
    }

    const searchVal = ref('')
    const setSearchVal = (val) => {
      searchVal.value = val
    }
    return {
      config,
      payList,
      gameList,
      selectedGame,
      selectedArea,
      selectedCategory,
      searchVal,
      setPayList,
      setConfig,
      setGameList,
      switchGameArea,
      switchCategory,
      setSearchVal,
    }
  },
  {
    persist: true,
  },
)
